package edu.rit.drh4818.raytracing.tone;

import java.awt.Color;

/**
 * @author Darren Headrick
 *
 */
public abstract class ToneReproduction 
{
	protected double lmax;
	
	public ToneReproduction( double lmax )
	{
		this.lmax = lmax;
	}
	
	public double calcLuminensce( int srgb )
	{
		return srgb * lmax / 255F;
	}
	
	public double calcLuminensce( Color c )
	{
		return (.27 * calcLuminensce(c.getRed())) + 
				(.67 * calcLuminensce(c.getGreen())) + 
				(.06 * calcLuminensce( c.getBlue()));
	}
	
	public double logAverage( Color[][] colors )
	{
		double totalLuminence = 0;
		
		for( int x = 0; x < colors.length; x++ )
		{
			for( int y = 0; y < colors[x].length; y++ )
			{
				totalLuminence += Math.log( .00000001 + calcLuminensce( colors[x][y]) );
			}
		}
		
		return Math.exp( totalLuminence / (colors.length*colors[0].length ) );
	}

	public abstract Color[][] transform( Color[][] original );
}
